// pages/orderlist/orderlist.js
let app = getApp();
const httpUtils = require('../../utils/httpUtils.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageurl: 'https://material.sse100.cn/shop/',
    page: 1,
    size: 20,
    showSearchResult:false,
    mData: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },
  getData: function () {
    let that = this
    wx.showLoading({
      title: '正在加载',
      mask: true
    })
    var info = JSON.stringify(this.data.id)
    console.log("info:" + info);
    httpUtils.orderlist({
      access_token: app.globalData.$TOKEN,
      page: that.data.page,
      size: that.data.size

    }).then((res) => {
      wx.hideLoading()
      if (that.data.page == 1) {
        that.data.mData.push(...res.data.list);
      } else {
        that.data.mData.push(...res.data.list);
      }
      that.data.page = that.data.page + 1;
      that.setData({
        mData: that.data.mData,
        page: that.data.page
      });
      if (that.data.mData.length >= res.data.total) {
        that.setData({
          showSearchResult: false
        })
      } else {
        that.setData({
          showSearchResult: true
        })
      }
     
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

 /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
        page: 1,
        mData: []
      }, () => {
        this.getData();
      });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 
   * 查看详情
   */
  lookdetail:function(e){
  
    // var canlook=e.currentTarget.dataset['canlook'];
    // if (!canlook) {
    //   return
    // }
    var id = e.currentTarget.dataset['id'];
    var orderno = e.currentTarget.dataset['orderno'];
    wx.navigateTo({
      url: '/pages/orderdetail/orderdetail?id='+id+'&order_no='+orderno,
    })

  },
  
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.showSearchResult==true) {
      console.log("11onReachBottom"+this.data.showSearchResult+this.data.page)
      this.getData();
    }
  },

  /**
   * 去课程列表界面
   */
  goMall:function(){
    wx.switchTab({
      url: '../allCourseList/allCourseList',
    })
  }
})